@extends('admin.layouts.content')
@section('script')
<script type="text/javascript" charset="utf-8">
  new Wanyue().layuiAdmin.form({
      list: [
          {type: 'hidden', title: '', name: '_token', verify: '', value: '{{csrf_token()}}' }
          , {type: 'checkbox', title: '选择角色', name: 'roles[]', verify: 'required',  list: {!! json_encode($roles) !!} }
      ]
  }, {
      url: {
          submit: '{{url()->current()}}'
      }
      , handler: function(layui) {
          var roles = {!! @json_encode($roles) !!};
          if (roles.length < 1) {
              layui.layer.msg('请先创建角色');
              return false;
          }
          var related = {!! @json_encode($related) !!};
          layui.$('input[type=checkbox]').each(function() {
              var that = layui.$(this);
              layui.each(related, function(index, item) {
                  if (item.role_id == that.val()) {
                      that.prop('checked', true);
                  }
              })
          });
      }
  });
</script>
@endsection

